<?php


// merchant公共函数文件
use app\common\service\promotion\PromotionMenuService;
use think\facade\Request;

/**
 * 菜单url获取
 * 应用/控制器/操作 
 * 
 * @return string eg：admin/Index/index
 */
function promotion_menu_url()
{
    return app('http')->getName() . '/' . Request::pathinfo();
}

/**
 * 菜单是否存在
 *
 * @param string $menu_url 菜单url
 *
 * @return bool
 */
function promotion_menu_is_exist($menu_url = '')
{
    if (empty($menu_url)) {
        $menu_url = promotion_menu_url();
    }
    $url_list = PromotionMenuService::menuList();
    if (in_array($menu_url, $url_list)) {
        return true;
    }

    return false;
}

/**
 * 菜单是否已禁用
 *
 * @param string $menu_url 菜单url
 *
 * @return bool
 */
function promotion_menu_is_disable($menu_url = '')
{
    if (empty($menu_url)) {
        $menu_url = promotion_menu_url();
    }

    $menu = PromotionMenuService::info($menu_url);
    if ($menu['is_disable'] == 1) {
        return true;
    }

    return false;
}

/**
 * 菜单是否免登
 *
 * @param string $menu_url 菜单url
 *
 * @return bool
 */
function promotion_menu_is_unlogin($menu_url = '')
{
    if (empty($menu_url)) {
        $menu_url = promotion_menu_url();
    }

    $unlogin_url = PromotionMenuService::unloginList();
    if (in_array($menu_url, $unlogin_url)) {
        return true;
    }

    return false;
}

/**
 * 菜单是否免权
 *
 * @param string $menu_url 菜单url
 *
 * @return bool
 */
function promotion_menu_is_unauth($menu_url = '')
{
    if (empty($menu_url)) {
        $menu_url = promotion_menu_url();
    }

    $unauth_url = PromotionMenuService::unauthList();
    if (in_array($menu_url, $unauth_url)) {
        return true;
    }

    return false;
}

/**
 * 菜单是否免限
 *
 * @param string $menu_url 菜单url
 *
 * @return bool
 */
function promotion_menu_is_unrate($menu_url = '')
{
    if (empty($menu_url)) {
        $menu_url = promotion_menu_url();
    }

    $unrate_url = PromotionMenuService::unrateList();
    if (in_array($menu_url, $unrate_url)) {
        return true;
    }

    return false;
}
